//
//  XS_Calculation.swift
//  Alamofire
//
//  Created by 韩云智 on 2020/7/14.
//
//  计算公式

import Foundation
import UIKit

public func *(left: CGSize, right: CGFloat) -> CGSize {
    return CGSize(width: left.width * right, height: left.height * right)
}
public func *(left: CGRect, right: CGFloat) -> CGRect {
    return CGRect(origin: left.origin * right, size: left.size * right)
}

// MARK:- CGRect
public func +(left: CGRect, right: CGPoint) -> CGRect {
    return CGRect(origin: left.origin + right, size: left.size)
}
public func +=(left: inout CGRect, right: CGPoint) {
    left = left + right
}

public func -(left: CGRect, right: CGPoint) -> CGRect {
    return CGRect(origin: left.origin - right, size: left.size)
}
public func -=(left: inout CGRect, right: CGPoint) {
    left = left - right
}

// MARK:- CGPoint
public func +(left: CGPoint, right: CGPoint) -> CGPoint {
    return CGPoint(x: left.x + right.x, y: left.y + right.y)
}
public func +=(left: inout CGPoint, right: CGPoint) {
    left = left + right
}

public func -(left: CGPoint, right: CGPoint) -> CGPoint {
    return CGPoint(x: left.x - right.x, y: left.y - right.y)
}
public func -=(left: inout CGPoint, right: CGPoint) {
    left = left - right
}

public func *(point: CGPoint, scalar: CGFloat) -> CGPoint {
    return CGPoint(x: point.x * scalar, y: point.y * scalar)
}
public func *=(point: inout CGPoint, scalar: CGFloat) {
    point = point * scalar
}

public func /(point: CGPoint, scalar: CGFloat) -> CGPoint {
    return CGPoint(x: point.x / scalar, y: point.y / scalar)
}
public func /=(point: inout CGPoint, scalar: CGFloat) {
    point = point / scalar
}

public func sqrt(a: CGFloat) -> CGFloat {
    return CGFloat(sqrtf(Float(a)))
}

public extension CGPoint {
    /// 坐标系长度
    func length() -> CGFloat { return sqrt(x*x + y*y) }
    /// 坐标系单位长度点
    func normalized() -> CGPoint { return self / length() }
}
